<?php
namespace app\obd\validate;

use think\Validate;

/**
 * Class CarValidate
 * @package app\obd\validate
 * obd/Car验证类
 * @author zhenHong~
 */
class CarValidate extends Validate{
    protected $rule = [
        'p_id' => ['require','regex' => '/^[+]{0,1}(\d+)$/'],
        'device_id' => ['require','regex' => '/^[+]{0,1}(\d+)$/'],
        'travel_id' => ['require','regex' => '/^[+]{0,1}(\d+)$/'],
        'pagenum' => ['require','regex' => '/^[+]{0,1}(\d+)$/'],
        'type' => ['require','checkMyType'],
        'car_id' => ['require','regex' => '/^[+]{0,1}(\d+)$/'],
        'listNum' => ['number'],
        'ID'      => ['require'],
        'P_ID'    => ['require'],
        'NAME'    => ['require'],
        'TYPE'    => ['require']
    ];

    protected $message = [
        'p_id' => '参数错误',
        'device_id' => '设备参数错误',
        'travel_id' => '行程参数错误',
        'pagenum' => '页数参数错误',
        'type' => '类型参数错误',
        'car_id' => '设备参数错误',
        'listNum' => '记录条数参数错误',
        'ID'      => 'ID不能为空',
        'P_ID'    => 'P_ID不能为空',
        'NAME'    => 'NAME不能为空',
        'TYPE'    => 'TYPE不能为空'
    ];
    protected $scene = [
        //查询车辆品牌
        'selectCarop' =>['p_id'],
        //删除车辆品牌
        'deleteCarop' =>['id'=>['require,number']],
        // 根据id修改车辆品牌名|车系名|车型名
        'editCar'          => ['ID','NAME'],
        // 根据上一级id添加新类别车系|车型|品牌
        'addCarName'       => ['P_ID','NAME','TYPE']
    ];

    /**
     * @param $value
     * @return bool
     * 检测type类型
     */
    protected function checkMyType($value){
        if($value == 'day' || $value == 'month' || $value == 'year'){
            return false;
        }else{
            return true;
        }
    }
}